Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./year1.RDS")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2020-03-14"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2020-03-28"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.25, n = 364)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 12.73926 12.75206 12.76453 12.77670 12.78861 12.80027 12.81173 12.82302
## [9] 12.83417 12.84520 12.85616 12.86706 12.87795 12.88886 12.89980 12.91074
## [17] 12.92157 12.93228 12.94286 12.95328 12.96354 12.97361 12.98348 12.99314
## [25] 13.00257 13.01175 13.02067 13.02931 13.03766 13.04570 13.05341 13.06078
## [33] 13.06779 13.07443 13.08068 13.08653 13.09221 13.09795 13.10372 13.10947
## [41] 13.11516 13.12075 13.12620 13.13147 13.13652 13.14132 13.14581 13.14996
## [49] 13.15373 13.15709 13.15998 13.16237 13.16421 13.16548 13.16612 13.16611
## [57] 13.16539 13.16437 13.16344 13.16252 13.16152 13.16037 13.15899 13.15730
## [65] 13.15521 13.15266 13.14956 13.14584 13.14140 13.13618 13.13010 13.12188
## [73] 13.11050 13.09627 13.07949 13.06047 13.03950 13.01690 12.99296 12.96798
## [81] 12.94227 12.91614 12.88988 12.86380 12.83821 12.81340 12.78967 12.76734
## [89] 12.74671 12.72807 12.71173 12.69800 12.68579 12.67385 12.66223 12.65096
## [97] 12.64009 12.62966 12.61971 12.61030 12.60145 12.59322 12.58564 12.57876
## [105] 12.57263 12.56728 12.56402 12.56395 12.56677 12.57220 12.57995 12.58974
## [113] 12.60128 12.61428 12.62846 12.64353 12.65920 12.67520 12.69123 12.70700
## [121] 12.72224 12.73665 12.74994 12.76184 12.77206 12.78030 12.78629 12.78973
## [129] 12.78557 12.77147 12.75125 12.72872 12.70770 12.69200 12.68544 12.68463
## [137] 12.68378 12.68305 12.68261 12.68264 12.68331 12.68480 12.68726 12.69089
## [145] 12.69584 12.70230 12.71043 12.72281 12.74099 12.76358 12.78918 12.81642
## [153] 12.84389 12.87022 12.89401 12.91388 12.93212 12.95176 12.97253 12.99415
## [161] 13.01637 13.03890 13.06146 13.08380 13.10564 13.12670 13.14671 13.16540
## [169] 13.18221 13.19726 13.21128 13.22500 13.23915 13.25448 13.27171 13.29158
## [177] 13.31409 13.33886 13.36552 13.39369 13.42298 13.45302 13.48344 13.51385
## [185] 13.54387 13.57313 13.60125 13.62786 13.65256 13.67499 13.69477 13.71152
## [193] 13.72486 13.73441 13.73979 13.74063 13.73985 13.73995 13.73998 13.73896
## [201] 13.73593 13.72992 13.71997 13.70510 13.68322 13.65406 13.61938 13.58096
## [209] 13.54055 13.49993 13.46087 13.42512 13.38072 13.31883 13.24590 13.16842
## [217] 13.09284 13.02563 12.97325 12.92886 12.88182 12.83296 12.78310 12.73306
## [225] 12.68367 12.63576 12.59014 12.54764 12.50908 12.47529 12.44708 12.42937
## [233] 12.42413 12.42784 12.43698 12.44800 12.45739 12.46161 12.45713 12.44043
## [241] 12.41570 12.38964 12.36253 12.33463 12.30618 12.27746 12.24872 12.22023
## [249] 12.19224 12.16501 12.13880 12.11387 12.08287 12.04118 11.99318 11.94328
## [257] 11.89584 11.85527 11.82595 11.80017 11.76872 11.73372 11.69729 11.66157
## [265] 11.62867 11.60072 11.57984 11.56816 11.56674 11.57369 11.58675 11.60365
## [273] 11.62212 11.63988 11.65467 11.67371 11.70420 11.74390 11.79055 11.84190
## [281] 11.89568 11.94964 12.00153 12.04908 12.09004 12.12215 12.14316 12.15688
## [289] 12.16862 12.17838 12.18619 12.19205 12.19596 12.19794 12.19873 12.19882
## [297] 12.19790 12.19562 12.19164 12.18563 12.17726 12.16618 12.15207 12.13302
## [305] 12.10843 12.07988 12.04893 12.01717 11.98616 11.95749 11.92540 11.88430
## [313] 11.83603 11.78246 11.72542 11.66676 11.60834 11.55199 11.49958 11.45294
## [321] 11.41393 11.38439 11.36087 11.33873 11.31807 11.29897 11.28151 11.26578
## [329] 11.25187 11.24356 11.24309 11.24828 11.25694 11.26687 11.27588 11.28178
## [337] 11.28237 11.27546 11.26498 11.25587 11.24752 11.23929 11.23056 11.22072
## [345] 11.20913 11.19659 11.18423 11.17194 11.15958 11.14704 11.13420 11.12092
## [353] 11.10709 11.09259 11.07730 11.06108 11.04383 11.02506 11.00457 10.98263
## [361] 10.95953 10.93552 10.91089 10.88591
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./site_objects/wrf_a_year1.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.25, n = 364)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 12.69955 12.68384 12.66830 12.65300 12.63803 12.62344 12.60930 12.59569
## [9] 12.58267 12.57031 12.55868 12.54785 12.53789 12.52887 12.52085 12.51379
## [17] 12.50755 12.50208 12.49734 12.49329 12.48988 12.48705 12.48477 12.48299
## [25] 12.48166 12.48073 12.48017 12.47992 12.47993 12.48017 12.48058 12.48111
## [33] 12.48173 12.48239 12.48303 12.48362 12.48467 12.48670 12.48961 12.49333
## [41] 12.49779 12.50289 12.50855 12.51471 12.52127 12.52815 12.53529 12.54258
## [49] 12.54996 12.55735 12.56466 12.57181 12.57872 12.58532 12.59151 12.59723
## [57] 12.60239 12.61079 12.62561 12.64581 12.67035 12.69820 12.72832 12.75969
## [65] 12.79125 12.82198 12.85085 12.87681 12.89883 12.91588 12.92691 12.93330
## [73] 12.93720 12.93879 12.93822 12.93567 12.93131 12.92530 12.91782 12.90902
## [81] 12.89909 12.88817 12.87646 12.86410 12.85128 12.83815 12.82489 12.81166
## [89] 12.79863 12.78598 12.77386 12.76245 12.74916 12.73177 12.71095 12.68737
## [97] 12.66172 12.63467 12.60690 12.57908 12.55190 12.52603 12.50215 12.48093
## [105] 12.46306 12.44921 12.43752 12.42575 12.41406 12.40255 12.39138 12.38066
## [113] 12.37054 12.36114 12.35259 12.34504 12.33860 12.33341 12.32961 12.32732
## [121] 12.32668 12.32782 12.33088 12.33597 12.34324 12.35282 12.36678 12.38596
## [129] 12.40861 12.43303 12.45748 12.48024 12.49958 12.51626 12.53237 12.54810
## [137] 12.56370 12.57936 12.59532 12.61179 12.62898 12.64712 12.66715 12.68961
## [145] 12.71413 12.74033 12.76784 12.79630 12.82531 12.85452 12.88355 12.91202
## [153] 12.93956 12.96580 12.99521 13.03120 13.07177 13.11497 13.15880 13.20130
## [161] 13.24048 13.27436 13.30098 13.32133 13.33836 13.35301 13.36623 13.37896
## [169] 13.39214 13.40670 13.42232 13.43796 13.45350 13.46883 13.48385 13.49845
## [177] 13.51250 13.52591 13.53856 13.55035 13.56116 13.57087 13.57939 13.58660
## [185] 13.59239 13.59665 13.59927 13.60014 13.59914 13.59675 13.59343 13.58910
## [193] 13.58367 13.57705 13.56916 13.55990 13.54919 13.53694 13.52260 13.50585
## [201] 13.48694 13.46613 13.44368 13.41985 13.39488 13.36903 13.34257 13.31574
## [209] 13.28880 13.26201 13.23307 13.20027 13.16481 13.12786 13.09059 13.05420
## [217] 13.01986 12.98373 12.94219 12.89672 12.84880 12.79992 12.75155 12.70519
## [225] 12.66231 12.62441 12.59001 12.55656 12.52394 12.49202 12.46065 12.42972
## [233] 12.39908 12.36860 12.33816 12.30761 12.27682 12.24567 12.21171 12.17353
## [241] 12.13257 12.09029 12.04811 12.00747 11.96982 11.93659 11.90923 11.88313
## [249] 11.85405 11.82394 11.79477 11.76848 11.74705 11.73241 11.72353 11.71785
## [257] 11.71513 11.71513 11.71761 11.72233 11.72902 11.73746 11.74740 11.75859
## [265] 11.77079 11.78375 11.80058 11.82328 11.84992 11.87859 11.90739 11.93440
## [273] 11.95771 11.98594 12.02660 12.07605 12.13064 12.18674 12.24072 12.28893
## [281] 12.32775 12.35353 12.37159 12.38921 12.40574 12.42053 12.43292 12.44225
## [289] 12.44786 12.44843 12.44359 12.43410 12.42074 12.40429 12.38553 12.36522
## [297] 12.34415 12.32309 12.30281 12.28410 12.26772 12.25050 12.22936 12.20515
## [305] 12.17877 12.15108 12.12298 12.09532 12.06900 12.04489 12.02235 12.00008
## [313] 11.97795 11.95583 11.93360 11.91113 11.88830 11.86498 11.84105 11.81638
## [321] 11.79084 11.76431 11.73309 11.69538 11.65390 11.61136 11.57047 11.53396
## [329] 11.50454 11.47766 11.44794 11.41689 11.38600 11.35677 11.33068 11.30923
## [337] 11.29392 11.28624 11.28401 11.28398 11.28597 11.28981 11.29535 11.30242
## [345] 11.31086 11.32058 11.33168 11.34426 11.35843 11.37431 11.39198 11.41157
## [353] 11.43318 11.45692 11.48289 11.51120 11.54195 11.57537 11.61149 11.65013
## [361] 11.69114 11.73435 11.77960 11.82672
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./site_objects/wrf_b_year1.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.25, n = 364)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 11.14981 11.19908 11.24741 11.29478 11.34120 11.38667 11.43119 11.47476
## [9] 11.51738 11.55906 11.59978 11.63955 11.67838 11.71625 11.75318 11.78916
## [17] 11.82419 11.85828 11.89141 11.92360 11.95484 11.98514 12.01448 12.04286
## [25] 12.07027 12.09671 12.12218 12.14667 12.17018 12.19271 12.21426 12.23482
## [33] 12.25439 12.27297 12.29055 12.30712 12.32270 12.33727 12.35083 12.36339
## [41] 12.37492 12.38544 12.39494 12.40327 12.41030 12.41608 12.42065 12.42406
## [49] 12.42634 12.42755 12.42772 12.42690 12.42513 12.42245 12.41892 12.41456
## [57] 12.40942 12.40356 12.39700 12.38979 12.38198 12.37361 12.36473 12.35537
## [65] 12.34440 12.33090 12.31518 12.29758 12.27842 12.25804 12.23676 12.21491
## [73] 12.19282 12.17083 12.14925 12.12841 12.10866 12.09031 12.06981 12.04378
## [81] 12.01282 11.97753 11.93849 11.89630 11.85157 11.80487 11.75682 11.70800
## [89] 11.65901 11.61044 11.56289 11.51695 11.47323 11.43230 11.39478 11.36125
## [97] 11.33231 11.30855 11.29058 11.27593 11.26185 11.24850 11.23603 11.22460
## [105] 11.21436 11.20546 11.19805 11.19230 11.18834 11.18634 11.18645 11.18882
## [113] 11.19360 11.20279 11.21781 11.23797 11.26257 11.29094 11.32238 11.35620
## [121] 11.39172 11.42824 11.46508 11.50155 11.53695 11.57060 11.60182 11.62990
## [129] 11.65733 11.68662 11.71710 11.74811 11.77901 11.80913 11.83781 11.86331
## [137] 11.88489 11.90332 11.91942 11.93398 11.94779 11.96167 11.97639 11.99277
## [145] 12.01160 12.03368 12.05981 12.09058 12.12542 12.16334 12.20334 12.24445
## [153] 12.28568 12.32604 12.36454 12.40021 12.43633 12.47623 12.51902 12.56379
## [161] 12.60963 12.65563 12.70089 12.74451 12.78556 12.82316 12.85639 12.88435
## [169] 12.91092 12.93969 12.96931 12.99842 13.02565 13.04964 13.06904 13.08432
## [177] 13.09698 13.10716 13.11502 13.12070 13.12436 13.12614 13.12620 13.12469
## [185] 13.12175 13.11754 13.11221 13.10591 13.09878 13.09099 13.08267 13.07398
## [193] 13.06507 13.05610 13.04720 13.03853 13.02887 13.01720 13.00400 12.98976
## [201] 12.97495 12.96006 12.94557 12.93195 12.92100 12.91341 12.90798 12.90352
## [209] 12.89885 12.89277 12.88410 12.87165 12.85904 12.84954 12.84144 12.83301
## [217] 12.82253 12.80829 12.78855 12.76456 12.73875 12.71116 12.68186 12.65089
## [225] 12.61830 12.58415 12.54850 12.51139 12.47288 12.43302 12.39187 12.34849
## [233] 12.30223 12.25357 12.20299 12.15096 12.09797 12.04450 11.99102 11.93801
## [241] 11.87758 11.80359 11.71914 11.62733 11.53125 11.43403 11.33874 11.24851
## [249] 11.16642 11.09559 11.03910 11.00007 10.96921 10.93681 10.90537 10.87735
## [257] 10.85525 10.84155 10.83873 10.85422 10.89041 10.94223 11.00462 11.07251
## [265] 11.14085 11.20455 11.25857 11.29782 11.33937 11.39891 11.46934 11.54355
## [273] 11.61446 11.67495 11.71794 11.75366 11.79589 11.84276 11.89243 11.94305
## [281] 11.99277 12.03975 12.08213 12.11806 12.14570 12.16320 12.16870 12.15428
## [289] 12.11808 12.06739 12.00951 11.95173 11.90134 11.86564 11.83296 11.78889
## [297] 11.73660 11.67924 11.62000 11.56202 11.50847 11.46252 11.42733 11.40170
## [305] 11.38105 11.36355 11.34735 11.33060 11.31145 11.28805 11.26046 11.23033
## [313] 11.19819 11.16461 11.13013 11.09528 11.06062 11.02670 10.99405 10.96323
## [321] 10.93478 10.90925 10.88019 10.84351 10.80328 10.76356 10.72842 10.70191
## [329] 10.68811 10.68620 10.69165 10.70292 10.71849 10.73681 10.75635 10.77559
## [337] 10.79298 10.80700 10.82102 10.83870 10.85894 10.88062 10.90264 10.92388
## [345] 10.94325 10.96172 10.98103 11.00119 11.02221 11.04408 11.06683 11.09045
## [353] 11.11495 11.14034 11.16662 11.19380 11.22190 11.25046 11.27915 11.30812
## [361] 11.33752 11.36750 11.39820 11.42978
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./site_objects/wrf_c_year1.rda")
keeping in case
#save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
#save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
#save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
#save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
#save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
#save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
#save(both_ymina, file = "./plotly_objs/both_ymina.rda")
#save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
#save(both_yminb, file = "./plotly_objs/both_yminb.rda")
#save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
#save(both_yminc, file = "./plotly_objs/both_yminc.rda")
#save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")